package com.googlecode.bip.entity;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Referent object : user view (read only)
 *
 * @author Claude CHOISNET
 */
public class Referent
    implements IReferent, Serializable
{
    private static final long serialVersionUID = 1L;
    private int idreferent;
    private String referentname;
    private String referentdescription;

    /**
     * Create an uninitialized Referent
     */
    public Referent()
    {
    }

    /**
     * Create a shadow copy of giving Referent
     *
     * @param o UserReferent to clone
     */
    public Referent( final Referent o )
    {
        this.idreferent             = o.idreferent;
        this.referentname           = o.referentname;
        this.referentdescription    = o.referentdescription;
    }

    /**
     * Initialize a Referent from ResultSet
     *
     * @param rSet
     * @return
     * @throws SQLException
     */
    public IReferent set( final ResultSet rSet ) throws SQLException
    {
        idreferent          = rSet.getInt( "idreferent" );
        referentname        = rSet.getString( "referentname" );
        referentdescription = rSet.getString( "referentdescription" );

        return this;
    }

    /* (non-Javadoc)
     * @see com.googlecode.bip.entity.IReferent#getIdReferent()
     */
    @Override
    final
    public int getIdReferent()
    {
        return this.idreferent;
    }

    /* (non-Javadoc)
     * @see com.googlecode.bip.entity.IReferent#setIdReferent(int)
     */
    //@Override
    protected void setIdReferent( int idreferent )
    {
        this.idreferent = idreferent;
    }

    /* (non-Javadoc)
     * @see com.googlecode.bip.entity.IReferent#getReferentName()
     */
    @Override
    final
    public String getReferentName()
    {
        return referentname;
    }

    /* (non-Javadoc)
     * @see com.googlecode.bip.entity.IReferent#setReferentName(java.lang.String)
     */
    //@Override
    protected void setReferentName( String referentname )
    {
        this.referentname = referentname;
    }

    /* (non-Javadoc)
     * @see com.googlecode.bip.entity.IReferent#getReferentDescription()
     */
    @Override
    final
    public String getReferentDescription()
    {
        return referentdescription;
    }

    /* (non-Javadoc)
     * @see com.googlecode.bip.entity.IReferent#setReferentDescription(java.lang.String)
     */
    //@Override
    protected void setReferentDescription( String referentdescription )
    {
        this.referentdescription = referentdescription;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result + idreferent;
        result = prime
                * result
                + ((referentdescription == null) ? 0 : referentdescription
                        .hashCode());
        result = prime * result
                + ((referentname == null) ? 0 : referentname.hashCode());
        return result;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals( Object obj )
    {
        if( this == obj ) return true;
        if( obj == null ) return false;
        if( getClass() != obj.getClass() ) return false;
        Referent other = (Referent)obj;
        if( idreferent != other.idreferent ) return false;
        if( referentdescription == null ) {
            if( other.referentdescription != null ) return false;
        } else if( !referentdescription.equals( other.referentdescription ) )
            return false;
        if( referentname == null ) {
            if( other.referentname != null ) return false;
        } else if( !referentname.equals( other.referentname ) ) return false;
        return true;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString()
    {
        StringBuilder builder = new StringBuilder();
        builder.append( "Referent [idreferent=" )
               .append( idreferent )
               .append( ", referentname=" )
               .append( referentname )
               .append( ", referentdescription=" )
               .append( referentdescription )
               .append( "]" );
        return builder.toString();
    }

}
